import socket
# 创建socket对象
socket_client = socket.socket()
# 连接服务端
socket_client.connect(("localhost", 8888))
print("服务端已连接")
while True:
    # 发送数据到服务端
    send_data = input("请输入发送内容：\n\t")
    if send_data == 'exit':
        socket_client.send('客户端已主动断开连接'.encode("UTF-8"))
        break
    socket_client.send(send_data.encode("UTF-8"))
    # 从服务端接收数据
    recv_data = socket_client.recv(1024)
    print(f"服务端回复：\n\t{recv_data.decode('UTF-8')}")
socket_client.close()